package com.leetcode.August;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @Description: 77. 组合
 * @Author: Mr.Fxy
 * @CreateTime: 2024-08-29 17:37
 */
public class LC77组合 {
    List<List<Integer>> res = new ArrayList<>();
    LinkedList<Integer> path = new LinkedList<>();
    public List<List<Integer>> combine(int n, int k) {
        backTracking(n, k, 1);
        return res;

    }
    private void backTracking(int n, int k, int i) {
        if (path.size()==k){
            res.add(new ArrayList<>(path));
            return;
        }
        for (int j = i; j <= n; j++) {
            path.add(j);
            backTracking(n, k, j+1);
            path.removeLast();
        }

    }
}
